<?php
// 本文档自动生成，仅供测试运行
class IndexAction extends Action
{
    /**
    +----------------------------------------------------------
    * 默认操作
    +----------------------------------------------------------
    */
	public function verify(){
		import("ORG.Util.Image");
		if(isset($_REQUEST['adv']))
                {
                        Image::showAdvVerify();
                }
                else
                {
                        Image::buildImageVerify();
                }
		}
/*
+----------------------------------------------------------------
用户登录，带验证码，令牌验证
+----------------------------------------------------------------
return void;
+----------------------------------------------------------------
*/
    public function log() 
	{   
		if($_SESSION['verify']!=md5($_POST['verify'])){
			$this->error('验证码错误');
			}
		else
		{
		$Demo = new Model('Demo');   // 实例化模型类   

		/*$Demo->Create(); // 创建数据对象   

		$result = $Demo->add(); // 写入数据库   */

		$condi['userName']=$_POST['userName'];

		$condi['passWord']=$_POST['passWord'];

		$Demo->where($condi)->select();

		if(!$Demo)
			{
				$this->error('账号或密码错误');
			}
		
		else
			{
				$this->assign("jumpUrl","/DownLoad/Down/index");
				Session::set(C('USER_AUTH_KEY'),$condi['userName']);
				//$this->display('DownLoad:Down:index','gbk');
				$this->redirect('toDown');  
			}
		
		
		}
	}	
	public function index() 
	{   

		/*$Demo = new Model('Demo'); // 实例化模型类   

		$list = $Demo->select(); // 查询数据   

		$this->assign('list',$list); // 模板变量赋值  */

		$this->display('LogIn/Index/index','gbk'); // 输出模板   

	}  
    /**
    +----------------------------------------------------------
    * 探针模式
    +----------------------------------------------------------
    */
    public function checkEnv()
    {
        load('pointer',THINK_PATH.'/Tpl/Autoindex');//载入探针函数
        $env_table = check_env();//根据当前函数获取当前环境
        echo $env_table;
    }
	/*
	+------------------------------------
	跳转至注册页面
	+------------------------------------
	*/
	public function jumpTo()
	{
		$this->display('Register:User:index','gbk');
	}
	//注册
	public function Insert()
	{
		if($_SESSION['verify']!=md5($_POST['verify'])){
			$this->error('验证码错误');
			}
		else
		{
			$Demo = new Model('Demo');   // 实例化模型类   

			$Demo->Create(); // 创建数据对象   

			$result = $Demo->add(); // 写入数据库   
			if(!$result)
			{
				$this->error('注册失败');
				$this->display('Register:User:index','gbk');
			}
			else
			{
				$this->display('LogIn:Index:index','gbk');
			}
			
		}
	}
	public function toDown()
	{
		if(!Session::is_set(C('USER_AUTH_KEY')))
		{
			$this->error('失败');
		}
		else
		{
			$msg=Session::get(C('USER_AUTH_KEY'));
			$this->assign('msg',$msg);
			$User=M("User");
			$list=$User->select();
		    $this->assign('list',$list);
			$this->display('DownLoad:Down:index','gbk');
		}
	}
	/*---------------------------------------------------------
	  文件上传功能，支持文件验证，数据库保存
	  +--------------------------------------------------------
	  return void;
	  ---------------------------------------------------------
	 */
	public function upload()
	{
		import("ORG.Net.UploadFile");
		$msg=Session::get(C('USER_AUTH_KEY'));
		$upload=new UploadFile();
			$savePath='Public/Uploads/Products/';
			$upload->savePath=$savePath;
			//缩略图生成
			$upload->thumb=true;
			$upload->thumbMaxWidth="50,200";
			$upload->thumbMaxHeight="50,200";
			$upload->thumbPath='Public/Uploads/Thumb/';
			//缩略图end
			$uploadReplace =  false;  //相同文件替换
			if(isset($_POST['_uploadReplace']) && 1==$_POST['_uploadReplace']) {
				//设置附件是否覆盖
				$upload->uploadReplace =  true;
				$uploadReplace = true;
			}
			if(!$upload->upload()){
				$this->error($upload->getErrorMsg());
			}else{
				$info= $upload->getUploadFileInfo();  //获得文件信息
			}
			$User=M("User");
			$User->create();
			$User->savename=$info[0]["savename"];
			$User->add();
			$list=$User->select();
		    $this->assign('list',$list);
            $this->display('DownLoad:Down:index','gbk');
	}
	public function download()
	{
		import("ORG.Net.Http");
		$name= $_POST['filename'];
		$savePath='Public/Uploads/Products/';
		$filename   = $savePath.$name;
		if(is_file($filename)){
			Http::download($filename,auto_charset($attach->name,'utf-8','gbk'));
		}
	}
}
?>